<?php
/*
* Copyright (c) 2010 by Cediti
*
* You may distribute under the terms of either the GNU Lesser General
* Public License or the new BSD License, as specified in the README file.
*/
// created :    09/02/2010
// version :    02/04/2010

class Cmis_Client_Rest_Generic_Navigation extends Cmis_Client_Rest_Generic_Abstract implements Cmis_Services_Protocol_Navigation
{
	public function getChildren(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $folderId, $maxItems = null, $skipCount = null, $orderBy = null, $filter = null, $includeRelationships = null, $renditionFilter = null, $includeAllowableActions = false, $includePathSegment = false)
	{
		/* @var $entry Cmis_Repository_Entry */
		$entry = $this->getServices()->getService('Object')->getObject($repositoryId, $folderId);
		$links = $entry->getLinks('down');
		$url = '';
		if ($links['multiple'])
		{
			foreach($links as $link)
			{
				if ($this->_checkTypeLink($link, self::FEED_TYPE_ATOM_FEED))
				{
					$url = $link['href'];
					break;
				}
			}
		}
		elseif ($this->_checkTypeLink($links, self::FEED_TYPE_ATOM_FEED))
		{
			$url = $links['href'];
		}

		if (Debug::is_active())
		{
			Debug::printTrace(1, 3);
			Debug::var_print(__METHOD__ . ' # ' . __LINE__);
			Debug::var_debug($links, $entry->getLinks(null));
		}

		if (empty($url))
		{
			throw new Cmis_Exception_Services_Navigation('No children links');
		}

		$params = array(
			'maxItems'					=> $maxItems,
			'skipCount'					=> $skipCount,
			'orderBy'					=> $orderBy,
			'filter'					=> $filter,
			'includeRelationships'		=> $includeRelationships,
			'renditionFilter'			=> $renditionFilter,
			'includeAllowableActions'	=> $includeAllowableActions,
			'includePathSegment'		=> $includePathSegment
		);
		$url = Cmis_ServiceUtils::buildUrl($url, $params);

		return $this->_callServices($url);
	}

	public function getDescendants(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $folderId, $depth = null, $filter = null, $includeRelationships = null, $renditionFilter = null, $includeAllowableActions = false, $includePathSegment = false)
	{
		//getCapapbilities('GetDescendants');
		die('-[Must be implemented : ' . __METHOD__ . ' (' . __FILE__ . '#' . __LINE__ . ')]-');
	}

	public function getFolderTree(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $folderId, $depth = null, $filter = null, $includeRelationships = null, $renditionFilter = null, $includeAllowableActions = false, $includePathSegment = false)
	{
		/* @var $entry Cmis_Repository_Entry */
		$entry = $this->getServices()->getService('Object')->getObject($repositoryId, $folderId);
		$link = $entry->getLinks('http://docs.oasis-open.org/ns/cmis/link/200908/foldertree');//, Cmis_Services_Interface::FEED_TYPE_ATOM_FEED);

		$params = array(
            'depth' => $depth,
            'filter'    => $filter,
            'includeRelationships'  => $includeRelationships,
            'renditionFilter'   => $renditionFilter,
            'includeAllowableActions'   => $includeAllowableActions,
            'includePathSegment'    => $includePathSegment
		);
		$url = Cmis_ServiceUtils::buildUrl($link['href'], $params);

		return $this->_callServices($url);
	}

	public function getFolderParent(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $folderId, $filter = null)
	{
		/* @var $entry Cmis_Repository_Entry */
		$entry = $this->getServices()->getService('Object')->getObject($repositoryId, $folderId, $filter);

		$parentId = $entry->getProperty('cmis:parentId');
		return $this->getServices()->getProtocolService('Object')->getObject($repositoryId, $parentId, $filter);
	}

	public function getObjectParents(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $objectId, $filter = null, $includeRelationships = null, $renditionFilter = null, $includeAllowableActions = false, $includeRelativePathSegment = false)
	{
		/* @var $entry Cmis_Repository_Entry */
		$entry = $this->getServices()->getService('Object')->getObject($repositoryId, $objectId, $filter, $includeRelationships, false, $renditionFilter, false, $includeAllowableActions);

		$up = $entry->getLinks('up');

		return $this->_callServices($up['href']);
	}

	public function getCheckedoutDocuments(Cmis_Repository_Id $repositoryId, Cmis_Repository_Id $folderId = null, $maxItems = null, $skipCount = null, $orderBy = null, $filter = null, $includeRelationships = null, $renditionFilter = null, $includeAllowableActions = false)
	{
		die('-[Must be implemented : ' . __METHOD__ . ' (' . __FILE__ . '#' . __LINE__ . ')]-');
	}
}

# EOF
